# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 0
n 0(None)[self.wdb = wydb
self.scheduler = scheduler
self.ref_wystandby = self.wdb.reference(config.standby_dbus_bus_name, config.standby_dbus_path_name)
self._AddStandbyModule = self.ref_wystandby.method('AddStandbyModule', 's', 's')
self._RemoveStandbyModule = self.ref_wystandby.method('RemoveStandbyModule', 's', 'i')
self.SetMaxPowerState = self.ref_wystandby.method('NotifyNewMaxPowerState', 'si', '')
self.SetPowerState = self.ref_wystandby.method('NotifyPowerStateChanged', 'si', '')
self.SetAlarm = self.ref_wystandby.method('SetAlarm', 'x', '')
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76ab98c>}
nname: 60
n 60(None)[return id
]:
	i: 3(), 30(), 58(AE)
	o: 

nname: 58
n 58(None)[]:
	i: 20(f)
	o: 60(AE)

nname: 30
n 30(None)[#, e
log.debug(str(e))
]:
	i: 20(t)
	o: 60()

nname: 20
n 20(<dummy_ex3> EXC_MATCH BaseException)[]:
	i: 0(except)
	o: 30(t), 58(f)

nname: 3
n 3(None)[return self._AddStandbyModule(id)
]:
	i: 0(try)
	o: 60()

nname: 0
n 0(None)[]:
	i: 
	o: 3(try), 20(except)

nname: 20
n 20(None)[except BaseException, e:
	log.debug(str(e))
return id
]:
	i: 0()
	o: 

nname: 0
n 0(None)[try:
	return self._AddStandbyModule(id)
]:
	i: 
	o: 20()

nname: 0
n 0(None)[try:
	return self._AddStandbyModule(id)
except BaseException, e:
	log.debug(str(e))
return id
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76a6fac>}
nname: 60
n 60(None)[return 0
]:
	i: 3(), 30(), 58(AE)
	o: 

nname: 58
n 58(None)[]:
	i: 20(f)
	o: 60(AE)

nname: 30
n 30(None)[#, e
log.debug(str(e))
]:
	i: 20(t)
	o: 60()

nname: 20
n 20(<dummy_ex3> EXC_MATCH BaseException)[]:
	i: 0(except)
	o: 30(t), 58(f)

nname: 3
n 3(None)[return self._RemoveStandbyModule(id)
]:
	i: 0(try)
	o: 60()

nname: 0
n 0(None)[]:
	i: 
	o: 3(try), 20(except)

nname: 20
n 20(None)[except BaseException, e:
	log.debug(str(e))
return 0
]:
	i: 0()
	o: 

nname: 0
n 0(None)[try:
	return self._RemoveStandbyModule(id)
]:
	i: 
	o: 20()

nname: 0
n 0(None)[try:
	return self._RemoveStandbyModule(id)
except BaseException, e:
	log.debug(str(e))
return 0
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76a6fcc>}
nname: 0
n 0(None)[log.debug('StateReadySignal')
self.scheduler.AsynchronousCheckSchedule()
self.SetPowerState(config.wystandby_id, APM_STATE_READY)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76a6fcc>}
nname: 0
n 0(None)[log.debug('StateStandbySignal')
self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76a6e4c>}
nname: 68
n 68(None)[]:
	i: 25(), 48()
	o: 

nname: 48
n 48(None)[self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)
]:
	i: 0(f)
	o: 68()

nname: 25
n 25(None)[self.SetPowerState(config.wystandby_id, APM_STATE_SUSPEND)
]:
	i: 0(t)
	o: 68()

nname: 0
n 0(self._ExternalStandby__is_standby_ready())[log.debug('StateSuspendSignal')
]:
	i: 
	o: 25(t), 48(f)

nname: 0
n 0(None)[log.debug('StateSuspendSignal')
if self._ExternalStandby__is_standby_ready():
	self.SetPowerState(config.wystandby_id, APM_STATE_SUSPEND)
else:
	self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76a6f2c>}
nname: 68
n 68(None)[]:
	i: 25(), 48()
	o: 

nname: 48
n 48(None)[self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)
]:
	i: 0(f)
	o: 68()

nname: 25
n 25(None)[self.SetPowerState(config.wystandby_id, APM_STATE_OFF)
]:
	i: 0(t)
	o: 68()

nname: 0
n 0(self._ExternalStandby__is_standby_ready())[log.debug('StateOffSignal')
]:
	i: 
	o: 25(t), 48(f)

nname: 0
n 0(None)[log.debug('StateOffSignal')
if self._ExternalStandby__is_standby_ready():
	self.SetPowerState(config.wystandby_id, APM_STATE_OFF)
else:
	self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76a6fac>}
nname: 111
n 111(None)[return True
]:
	i: 94(), 110()
	o: 

nname: 110
n 110(None)[]:
	i: 24(f)
	o: 111()

nname: 94
n 94(None)[self.SetAlarm(time)
]:
	i: 55(), 75()
	o: 111()

nname: 75
n 75(None)[time = int(time.time())
]:
	i: 45(f)
	o: 94()

nname: 55
n 55(None)[time = rec.start_time - rec.start_padding
]:
	i: 45(t)
	o: 94()

nname: 45
n 45(rec.start_time)[]:
	i: 24(t)
	o: 55(t), 75(f)

nname: 24
n 24(rec)[rec = self.scheduler.GetFirstRecordingToStart()
]:
	i: 15(), 23()
	o: 45(t), 110(f)

nname: 23
n 23(None)[]:
	i: 0(f)
	o: 24()

nname: 15
n 15(None)[return False
]:
	i: 0(t)
	o: 24()

nname: 0
n 0(self.scheduler.IsSomeRecordingRunning())[]:
	i: 
	o: 15(t), 23(f)

nname: 111
n 111(None)[return True
]:
	i: 45(), 0(f)
	o: 

nname: 45
n 45(None)[if rec.start_time:
	time = rec.start_time - rec.start_padding
else:
	time = int(time.time())
self.SetAlarm(time)
]:
	i: 0(t)
	o: 111()

nname: 0
n 0(rec)[if self.scheduler.IsSomeRecordingRunning():
	return False
rec = self.scheduler.GetFirstRecordingToStart()
]:
	i: 
	o: 45(t), 111(f)

nname: 0
n 0(None)[if self.scheduler.IsSomeRecordingRunning():
	return False
rec = self.scheduler.GetFirstRecordingToStart()
if rec:
	if rec.start_time:
		time = rec.start_time - rec.start_padding
	else:
		time = int(time.time())
	self.SetAlarm(time)
return True
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76ab96c>}
nname: 6
n 6(None)[def __init__(self, wydb, scheduler=None):
	self.wdb = wydb
	self.scheduler = scheduler
	self.ref_wystandby = self.wdb.reference(config.standby_dbus_bus_name, config.standby_dbus_path_name)
	self._AddStandbyModule = self.ref_wystandby.method('AddStandbyModule', 's', 's')
	self._RemoveStandbyModule = self.ref_wystandby.method('RemoveStandbyModule', 's', 'i')
	self.SetMaxPowerState = self.ref_wystandby.method('NotifyNewMaxPowerState', 'si', '')
	self.SetPowerState = self.ref_wystandby.method('NotifyPowerStateChanged', 'si', '')
	self.SetAlarm = self.ref_wystandby.method('SetAlarm', 'x', '')

def AddStandbyModule(self, id):
	try:
		return self._AddStandbyModule(id)
	except BaseException, e:
		log.debug(str(e))
	return id

def RemoveStandbyModule(self, id):
	try:
		return self._RemoveStandbyModule(id)
	except BaseException, e:
		log.debug(str(e))
	return 0

def treat_StateReadySignal(self):
	log.debug('StateReadySignal')
	self.scheduler.AsynchronousCheckSchedule()
	self.SetPowerState(config.wystandby_id, APM_STATE_READY)

def treat_StateStandbySignal(self):
	log.debug('StateStandbySignal')
	self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)

def treat_StateSuspendSignal(self):
	log.debug('StateSuspendSignal')
	if self._ExternalStandby__is_standby_ready():
		self.SetPowerState(config.wystandby_id, APM_STATE_SUSPEND)
	else:
		self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)

def treat_StateOffSignal(self):
	log.debug('StateOffSignal')
	if self._ExternalStandby__is_standby_ready():
		self.SetPowerState(config.wystandby_id, APM_STATE_OFF)
	else:
		self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)

def _ExternalStandby__is_standby_ready(self):
	if self.scheduler.IsSomeRecordingRunning():
		return False
	rec = self.scheduler.GetFirstRecordingToStart()
	if rec:
		if rec.start_time:
			time = rec.start_time - rec.start_padding
		else:
			time = int(time.time())
		self.SetAlarm(time)
	return True

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb76a69ec>}
nname: 0
n 0(None)[from logger import log
from config import *
from peewee.analyse import Chrono
from peewee.analyse import timestep
class ExternalStandby(object):
	def __init__(self, wydb, scheduler=None):
		self.wdb = wydb
		self.scheduler = scheduler
		self.ref_wystandby = self.wdb.reference(config.standby_dbus_bus_name, config.standby_dbus_path_name)
		self._AddStandbyModule = self.ref_wystandby.method('AddStandbyModule', 's', 's')
		self._RemoveStandbyModule = self.ref_wystandby.method('RemoveStandbyModule', 's', 'i')
		self.SetMaxPowerState = self.ref_wystandby.method('NotifyNewMaxPowerState', 'si', '')
		self.SetPowerState = self.ref_wystandby.method('NotifyPowerStateChanged', 'si', '')
		self.SetAlarm = self.ref_wystandby.method('SetAlarm', 'x', '')

	def AddStandbyModule(self, id):
		try:
			return self._AddStandbyModule(id)
		except BaseException, e:
			log.debug(str(e))
		return id

	def RemoveStandbyModule(self, id):
		try:
			return self._RemoveStandbyModule(id)
		except BaseException, e:
			log.debug(str(e))
		return 0

	def treat_StateReadySignal(self):
		log.debug('StateReadySignal')
		self.scheduler.AsynchronousCheckSchedule()
		self.SetPowerState(config.wystandby_id, APM_STATE_READY)

	def treat_StateStandbySignal(self):
		log.debug('StateStandbySignal')
		self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)

	def treat_StateSuspendSignal(self):
		log.debug('StateSuspendSignal')
		if self._ExternalStandby__is_standby_ready():
			self.SetPowerState(config.wystandby_id, APM_STATE_SUSPEND)
		else:
			self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)

	def treat_StateOffSignal(self):
		log.debug('StateOffSignal')
		if self._ExternalStandby__is_standby_ready():
			self.SetPowerState(config.wystandby_id, APM_STATE_OFF)
		else:
			self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)

	def _ExternalStandby__is_standby_ready(self):
		if self.scheduler.IsSomeRecordingRunning():
			return False
		rec = self.scheduler.GetFirstRecordingToStart()
		if rec:
			if rec.start_time:
				time = rec.start_time - rec.start_padding
			else:
				time = int(time.time())
			self.SetAlarm(time)
		return True



]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb769fe8c>}
from logger import log
from config import *
from peewee.analyse import Chrono
from peewee.analyse import timestep
class ExternalStandby(object):
	def __init__(self, wydb, scheduler=None):
		self.wdb = wydb
		self.scheduler = scheduler
		self.ref_wystandby = self.wdb.reference(config.standby_dbus_bus_name, config.standby_dbus_path_name)
		self._AddStandbyModule = self.ref_wystandby.method('AddStandbyModule', 's', 's')
		self._RemoveStandbyModule = self.ref_wystandby.method('RemoveStandbyModule', 's', 'i')
		self.SetMaxPowerState = self.ref_wystandby.method('NotifyNewMaxPowerState', 'si', '')
		self.SetPowerState = self.ref_wystandby.method('NotifyPowerStateChanged', 'si', '')
		self.SetAlarm = self.ref_wystandby.method('SetAlarm', 'x', '')

	def AddStandbyModule(self, id):
		try:
			return self._AddStandbyModule(id)
		except BaseException, e:
			log.debug(str(e))
		return id

	def RemoveStandbyModule(self, id):
		try:
			return self._RemoveStandbyModule(id)
		except BaseException, e:
			log.debug(str(e))
		return 0

	def treat_StateReadySignal(self):
		log.debug('StateReadySignal')
		self.scheduler.AsynchronousCheckSchedule()
		self.SetPowerState(config.wystandby_id, APM_STATE_READY)

	def treat_StateStandbySignal(self):
		log.debug('StateStandbySignal')
		self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)

	def treat_StateSuspendSignal(self):
		log.debug('StateSuspendSignal')
		if self._ExternalStandby__is_standby_ready():
			self.SetPowerState(config.wystandby_id, APM_STATE_SUSPEND)
		else:
			self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)

	def treat_StateOffSignal(self):
		log.debug('StateOffSignal')
		if self._ExternalStandby__is_standby_ready():
			self.SetPowerState(config.wystandby_id, APM_STATE_OFF)
		else:
			self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)

	def _ExternalStandby__is_standby_ready(self):
		if self.scheduler.IsSomeRecordingRunning():
			return False
		rec = self.scheduler.GetFirstRecordingToStart()
		if rec:
			if rec.start_time:
				time = rec.start_time - rec.start_padding
			else:
				time = int(time.time())
			self.SetAlarm(time)
		return True



